package collectorserver

import (
	"fmt"
	"slices"
)

type User struct {
	name  string
	email string
}

func (u *User) GetName() string {
	return u.name
}

func (u *User) SetName(name string) {
	u.name = name
}

func UserProperties(username string) (string, string, string, User) {
	user := User{name: "soltex", email: "sdfsdf"}
	return username + "123123", username + "33e3", username + username, user
}

func UserProperties1(val int, values []int) int {
	if values == nil {
		fmt.Println("values is nil")
	} else {
		for i := 0; i < len(values); i++ {
			fmt.Printf("values[%d] is %d\n", i, values[i])
		}
	}

	if val == 1 {
		return val + val
	} else {
		return val * val
	}
}

func CalGrade(score float32) (grade string, finalScore float32) {
	if score > 100 {
		finalScore = 100
	} else if score < 0 {
		finalScore = 0
	} else {
		finalScore = score
	}
	switch {
	case finalScore <= 100 && finalScore >= 90:
		grade = "A"
		break
	case finalScore < 90 && finalScore >= 80:
		grade = "B"
		break
	case finalScore < 80 && finalScore >= 70:
		grade = "C"
		break
	case finalScore < 70 && finalScore >= 60:
		grade = "D"
		break
	default:
		grade = "E"
	}
	return grade, finalScore
}
func CalComplexResult(x complex128, y complex128) complex128 {
	return x * y
}

func CalResult2(a []int) {
	for _, val := range a {
		fmt.Printf("val is %d\n", val)
	}
}
func CalResult1(a ...int) {
	for index, v := range a {
		fmt.Println(index, v)
	}
}

// CalResult4
//
//	计算 4
//	@Description:
//	@param f1
//	@param f2
//	@param f
//	@return float32
func CalResult4(f1 float32, f2 float32, f func(result float32) float32) float32 {
	fmt.Printf("CalResult4 f1 %f , f2 %f \n", f1, f2)
	return f(f1 * f2)
}

// Ops
//
//	@Description: 	加减乘除操作
//	@param f1
//	@param f2
//	@param calculator
//	@return float32
func Ops(f1 float32, f2 float32, calculator Calculator) float32 {
	return calculator.Cal(f1, f2)
}

// Filter
//
//	@Description: 过滤器
//	@param list
//	@param f
//	@return []int
func Filter(list []int, f func(list []int)) []int {
	if f == nil {
		f = func(list []int) {

		}
	}
	return list
}

// CalScore
//
//	@Description: 	计算得分
//	@param score
//	@return sum
//	@return avg
//	@return max
//	@return min
func CalScore(score ...float32) (sum float32, avg float32, max float32, min float32) {
	if score == nil {
		return 0, 0, 0, 0
	}
	//	计算总分
	sum = 0
	for _, value := range score {
		sum = sum + value
	}
	avg = sum / float32(len(score))
	max = slices.Max(score)
	min = slices.Min(score)
	return sum, avg, max, min
}

// MuliByN
//
//	@Description:   1x2x3x4x5x6
//	@param n
func MuliByN(n int) int {
	if n == 0 {
		return 1
	}
	return n * MuliByN(n-1)
}

// ChangeValue
//
//	@Description:  更换外面的值
//	@param pv
//	@param newValue
func ChangeValue(pv *int, newValue int) {
	*pv = newValue
}

// ChangeValue2
//
//	@Description: 	转换为新的值
//	@param v
//	@param newValue
func ChangeValue2(v int, newValue int) {
	v = newValue
}
